package alpaca.network;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;


/**
 * The Interface IClientConnection.
 * Any class that implements IClientConnection needs to send updates with {@link PropertyChangeSupport}
 * by using the SystemMessage class as the value "newValue". Any connections or disconnects needs to be updated. 
 * Also every object that get sent to the server needs to be passed on through it.
 * 
 */
public interface IClientConnection {
	
	/**
	 * Adds the property change listener. The ClientConnection should send updates and every
	 * received message through {@link PropertyChangeSupport}
	 *
	 * @param pcl the class which is to be added 
	 */
	void addPropertyChangeListener(PropertyChangeListener pcl);
	
	/**
	 * Removes the property change listener.
	 *
	 * @param pcl the class which is to be added 
	 */
	void removePropertyChangeListener(PropertyChangeListener pcl);
	
	/**
	 * Sends the object to the specified ID mapped by the ClientConnection.
	 *
	 * @param connID the connection ID for a connected client
	 * @param nm the NetworkMessage object
	 */
	void send(int connID, NetworkMessage nm);
		
	/**
	 * Starts the server. If for an example a port is already occupied or it
	 * failed in any other way an {@link IOException} should be thrown.
	 *
	 * @param port the port on wish the server is to accept connections on
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	void start(int port) throws IOException;
	
	/**
	 * Stops the server.
	 */
	void stop();
	
	/**
	 * Forcefully closes a connected clients connection to the server.
	 *
	 * @param connID the connection ID for a connected client
	 */
	void closeConnection(int connID);

	
	
}
